import { Button } from 'antd'
import { useRequest } from 'ahooks'
import { useCallback, useEffect, useState } from 'react'
import SetRootIdSearch from './SetRootIdSearch';
import SetRootIdList from './SetRootIdList';
import { getAdminListApi } from '@/api/auth'
import SetRootIdAdd from './SetRootIdAdd';

const SetRootId = () => {
  const [isModalOpen, setModalOpen] = useState(false)
  const [adminList, setAdminList] = useState()
  const { data, loading, run: getAdminList } = useRequest(getAdminListApi)
  const handleAdminGroup = useCallback((isShow, reset = false) => {
    setModalOpen(isShow)
    if (reset) {
      getAdminList()
      console.log(111)
    }
  })
  useEffect(() => {
    setAdminList(data)
  }, [data])
  return (
    <>
      <SetRootIdSearch setAdminList={setAdminList} getAdminList={getAdminList} />
      <hr />
      <Button type="primary" style={{ margin: '20px 0 0 20px' }} onClick={() => setModalOpen(true)}>新增</Button>
      <SetRootIdAdd isModalOpen={isModalOpen} handleAdminGroup={handleAdminGroup} />
      <SetRootIdList adminList={adminList} loading={loading} getAdminList={getAdminList} handleAdminGroup={handleAdminGroup} />
    </>
  )
}

export default SetRootId;
